﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class SubusersController : UserController
    {
        [Authorize]
        [HttpGet]
        public IActionResult Get(int id)
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                return Ok(new { status = 0, msg = "用户尚未登录或已超时！" });
            }
            if (id < userModel.id)
                id = userModel.id;
            var users = _users.GetListIid(id);
            var sys = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            for (int i = 0; i < users.Count; i++)
            {
                users[i].avatar = sys.weburl + users[i].avatar;
            }
            return Ok(new { status = 1, list = users });
        }
    }
}